package com.yzt.plugin_network.excep;

import android.text.TextUtils;

import com.yzt.p_base.AppUtils;
import com.yzt.p_base.BuildConfig;
import com.yzt.plugin_network.R;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class HttpErrorMsg {

    public static String getHttpErrorMessage(int code, String msg) {
        switch (code) {
            case HttpStatus.HttpCode.REQUEST_SYNTAX:
                //请求出现语法错误
                if (TextUtils.isEmpty(msg)) {
                    msg = AppUtils.getApp().getString(R.string.server_is_wandering);
                }
                break;
            case HttpStatus.HttpCode.REQUEST_REFUSE:
                //访问被拒绝
                msg = AppUtils.getApp().getString(R.string.access_to_the_server_is_denied);
                break;
            case HttpStatus.HttpCode.REQUEST_FORBID:
                //禁止访问
                msg = AppUtils.getApp().getString(R.string.the_server_prohibits_your_access);
                break;
            case HttpStatus.HttpCode.ADDRESS_ERROR:
                //服务器请求失败
                msg = AppUtils.getApp().getString(R.string.request_server_failed);
                break;
            case HttpStatus.HttpCode.ADDRESS_NOT_FOUNT:
                //找不到
                msg = AppUtils.getApp().getString(R.string.your_device_or_account_has_been_banned);

                break;
            case HttpStatus.HttpCode.SERVER_ERROR:
                //服务器错误
                msg = AppUtils.getApp().getString(R.string.server_is_wandering);
                break;
            case HttpStatus.HttpCode.SERVER_NOT_HOLD:
                //服务器不支持实现请求所需要的功能
                msg = AppUtils.getApp().getString(R.string.the_server_does_not_support_the_function_required_to_implement_the_request);
                break;
            case HttpStatus.HttpCode.SERVER_GATEWAY_ERROR:
                //服务器网关错误
                msg = AppUtils.getApp().getString(R.string.the_server_does_not_support_the_function_required_to_implement_the_request);
                break;
            case HttpStatus.HttpCode.SERVER_MAINTAIN:
                //服务器维护
                msg = AppUtils.getApp().getString(R.string.the_server_did_not_answer_please_try_again_later);
                break;
            case HttpStatus.HttpCode.TOKEN_INVALID:
                //token过期
                msg = AppUtils.getApp().getString(R.string.login_information_has_expired_please_login_again);
                break;
            default:
                if (TextUtils.isEmpty(msg)) {
                    if (!BuildConfig.DEBUG) {
                        msg = "";
                    } else {
                        msg = AppUtils.getApp().getString(R.string.failed_to_request_data_please_try_again_later);
                    }
                }
                break;
        }
        return msg;
    }

    public static String getErrorMessage(int code, String msg) {
        switch (code) {
            case HttpStatus.ResponseStatus.TOKEN_INVALID:
                //token过期
                msg = AppUtils.getApp().getString(R.string.login_information_has_expired_please_login_again);
                break;
            case HttpStatus.ResponseStatus.NODATA:
                //没有获取到数据
                msg = AppUtils.getApp().getString(R.string.no_data_fond);
                break;
            case HttpStatus.ResponseStatus.VERIFICATION_INVALID:
                //验证码错误
                msg = AppUtils.getApp().getString(R.string.verify_code_error_try_again);
                break;
            case HttpStatus.ResponseStatus.PARAMETER_ERROR:
                //参数错误
                break;
            case HttpStatus.ResponseStatus.PWD_ERROR:
                msg = AppUtils.getApp().getString(R.string.pwd_error);
                break;
            case HttpStatus.ResponseStatus.RLY_LOGIN_ERROR:
                msg = AppUtils.getApp().getString(R.string.login_info_exception);
                break;
            case HttpStatus.ResponseStatus.NO_NETWORK:
                msg = AppUtils.getApp().getString(R.string.unable_to_connect_to_the_network_temporarily);
                break;
            case HttpStatus.ResponseStatus.SYSTEM_ERROR:
                //系统异常
                msg = AppUtils.getApp().getString(R.string.server_is_wandering);
                break;
            case HttpStatus.ResponseStatus.ACCOUNT_NOT_OPEN:
                msg = AppUtils.getApp().getString(R.string.the_account_has_not_been_opened);
                break;
            case HttpStatus.HttpCode.REQUEST_SYNTAX:
                //请求出现语法错误
                if (TextUtils.isEmpty(msg)) {
                    msg = AppUtils.getApp().getString(R.string.server_is_wandering);
                }
                break;
            case HttpStatus.HttpCode.REQUEST_REFUSE:
                //访问被拒绝
                msg = AppUtils.getApp().getString(R.string.access_to_the_server_is_denied);
                break;
            case HttpStatus.HttpCode.REQUEST_FORBID:
                //禁止访问
                msg = AppUtils.getApp().getString(R.string.the_server_prohibits_your_access);
                break;
            case HttpStatus.HttpCode.ADDRESS_ERROR:
                //你懂的
                msg = AppUtils.getApp().getString(R.string.request_server_failed);
                break;
            case HttpStatus.HttpCode.ADDRESS_NOT_FOUNT:
                //找不到
                msg = AppUtils.getApp().getString(R.string.your_device_or_account_has_been_banned);
                break;
            case HttpStatus.HttpCode.SERVER_ERROR:
                //服务器错误
                msg = AppUtils.getApp().getString(R.string.server_is_wandering);
                break;
            case HttpStatus.HttpCode.SERVER_NOT_HOLD:
                //服务器不支持实现请求所需要的功能
                msg = AppUtils.getApp().getString(R.string.the_server_does_not_support_the_function_required_to_implement_the_request);
                break;
            case HttpStatus.HttpCode.SERVER_GATEWAY_ERROR:
                //服务器网关错误
                msg = AppUtils.getApp().getString(R.string.the_server_does_not_support_the_function_required_to_implement_the_request);
                break;
            case HttpStatus.HttpCode.SERVER_MAINTAIN:
                //服务器维护
                msg = AppUtils.getApp().getString(R.string.the_server_did_not_answer_please_try_again_later);
                break;
            default:
                if (TextUtils.isEmpty(msg)) {
                    if (!BuildConfig.DEBUG) {
                        msg = "";
                    } else {
                        msg = AppUtils.getApp().getString(R.string.failed_to_request_data_please_try_again_later);
                    }
                }
                break;
        }
        return msg;
    }
}
